<template>
  <div class="container">
    <!-- 公共头部 -->
    <van-nav-bar
      fixed
      v-if="isShow"
      title="每日一笑"
      @click-right="$router.push('/search')"
    >
      <template #left>
        <van-icon name="envelop-o" size="18" />
      </template>
      <template #right>
        <van-icon name="search" size="18" />
      </template>
    </van-nav-bar>

    <!-- 渲染四个标签的二级路由 -->
    <div class="my-wrapper" :class="{ noTop: !isShow }">
            <!-- <keep-alive>
            <router-view v-if="this.$route.meta.isKeepAlive" />
            </keep-alive>
            <router-view v-if="!this.$route.meta.isKeepAlive" /> -->
        <!-- keep-alive 控制缓存组件 -->
      <keep-alive include="home-index,user-index">
        <router-view />
      </keep-alive>
    </div>

    <!-- 公共底部标签 -->
    <van-tabbar route>
      <van-tabbar-item to="/" icon="wap-home"> 首页 </van-tabbar-item>
      <van-tabbar-item to="/question" icon="question"> 问答 </van-tabbar-item>
      <van-tabbar-item to="/video" icon="play-circle"> 视频 </van-tabbar-item>
      <van-tabbar-item to="/user" icon="manager"> 我的 </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: 'layout',
  // 通过计算属性来判断跳转的路由是否携带hash，然后在来判断是否显示头部标签
  computed: {
    isShow () {
      return this.$route.path !== '/user'
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  position: relative;
  .my-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding-top: 46px;
    padding-bottom: 50px;
    box-sizing: border-box;
    &.noTop {
      padding-top: 0;
    }
  }
}
</style>
